<div class="section">

	<div class="section-title">Quản lý khách hàng</div>
    
    <div class="section-content">
    	
        <form action="" method="post" id="listitem" name="listitem">
        
        	<div class="right">
                <a class="button add" href="<?php echo $insert?>">Thêm mới</a>
                <a class="button delete" onclick="deleteItem()">Xóa</a>
                <a class="button exit" href="?route=deliman/home">Về trang chủ</a>   
            </div>
            <div class="clearer">^&nbsp;</div>
            <div id="ben-search">
                <div class="left">
                    <label>Họ tên khách hàng:  </label>
                    <input type="text" id="hoten" name="hoten" class="text" />&nbsp;&nbsp;&nbsp;&nbsp; 
                </div>
                <div class="left">
                    <label>Khu vực:</label>
                    <select id="khuvuc" name="khuvuc">
                    <option value="">Chọn khu vực</option>
                    <?php foreach($khuvucs as $khuvuc){ ?>
                    <option value="<?php echo $khuvuc['khuvucid']?>"><?php echo $this->string->getPrefix("&nbsp; &nbsp; &nbsp; &nbsp;",$khuvuc['level']);?><?php echo $khuvuc['tenkhuvuc']?></option>
                    <?php }?>
                    </select>&nbsp;&nbsp;&nbsp;&nbsp;         
                </div>
                <div class="left">
                    <a class="button-other search" onClick="searchForm()">Tìm kiếm</a>
                    <a class="button all" href="?route=deliman/khachhang">Xem tất cả</a>
                </div>
            	<div class="clearer">^&nbsp;</div>
            </div>
            <div class="sitemap treeindex">
                <table class="data-table" cellpadding="0" cellspacing="0">
                <tbody>
                    <tr class="tr-head">
                        <th width="1%"><input class="inputchk" type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"></th>
                        
                        <th>Tên khách hàng</th>
                        <th>Địa chỉ</th>
                        <th>Ghi chú</th>
                        <th>Số lượng báo đã đặt</th>
                        <th width="240px">Công cụ</th>                                  
                    </tr>
        <?php
         if($thongbaotimkiem==0)
            {
        ?>
        	<tr>
            	<td colspan="7">
                <div class="text-center">
            		<span class="thongbaokhongcodulieu">Không có dữ liệu trong hệ thống</span>
                </div>
                </td>
            </tr>
        
        <?php 
        }else{
        ?>
        
        <?php
            foreach($datas as $item)
            {
        ?>
                    <tr>
                        <td class="check-column"><input class="inputchk" type="checkbox" name="delete[<?php echo $item['khachhangid']?>]" value="<?php echo $item['khachhangid']?>" ></td>
                        
                        <td><?php echo $item['hoten']?></td>
                     	<td><?php echo $item['diachi']?></td>
                        <td><?php echo $item['ghichu']?></td>
                        <?php
                        	if($item['soluongdat'] != 0)
                            {
                        ?>
                        <td><?php echo $item['soluongdat']?></td>
                        <?php
                        	}else{
                        ?>
                        <td style="color:white; background:red; font-family:Tahoma, Geneva, sans-serif; font-weight:bold"><?php echo 'Chưa đặt báo'?></td>
                        <?php
                        	}
                        ?>
                        <td class="link-control">
                            <a class="button edit" href="<?php echo $item['link_edit']?>">Sửa</a>
                        	<a class="button get" href="<?php echo $item['link_order'] ?>">Đặt báo</a>
                           	<a class="button-other search" href="<?php echo $item['link_vieworder'] ?>">
                            	Xem thông tin đặt báo
                            </a>
                        </td>
                    </tr>
        <?php
        	}
        }           
        ?>
            
        
                                                    
                </tbody>
                </table>
            </div>
        	<?php echo $pager?>
        
        </form>
        
    </div>
    
</div>
<script language="javascript">
function deleteItem()
{
	var answer = confirm("Bạn có muốn xóa không?")
	if (answer)
	{
		$.post("?route=deliman/khachhang/delete", 
				$("#listitem").serialize(), 
				function(data)
				{
					if(data=="true")
					{
						alert("Xóa thành công");
						window.location.reload();
					}
				}
		);
	}
}

function searchForm()
{
	var url =  "?route=deliman/khachhang";
		
	if($("#hoten").val() != "")
		url += "&hoten="+ $("#hoten").val();
	if($("#khuvuc").val() != "")
		url += "&khuvuc=" + $("#khuvuc").val();

	window.location = url;
}

$("#hoten").val("<?php echo urldecode($_GET['hoten'])?>");
$("#khuvuc").val("<?php echo $_GET['khuvuc']?>");
</script>